package net.neocoin.clazz;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;

/**
 * @since JDK 1.5
 * @author neocoin
 */
public class ClassUtils {
	public static URL getClassPathUrl(Object object) {
		Class<? extends Object> clazz = object.getClass();
		String[] split = clazz.getName().split("\\.");
		URL url = clazz.getResource(split[split.length - 1] + ".class");
		return url;
	}

	public static File getClassPathParentFile(Object object) throws URISyntaxException {
		return new File(getClassPathUrl(object).toURI()).getParentFile();
	}

	public static String getCurrentMethodName() {
		return Thread.currentThread().getStackTrace()[2].getMethodName();
	}

	public static String getCurrentFilename() {
		return Thread.currentThread().getStackTrace()[2].getFileName();
	}

	public static StackTraceElement getCurrentStackElement() {
		return Thread.currentThread().getStackTrace()[2];
	}

	public static int getCurrentLine() {
		return Thread.currentThread().getStackTrace()[2].getLineNumber();
	}
}
